import request from '@/utils/monitor'
import { log } from './log.js'

export function saveDevice(data) {
  const logData = {
    data: JSON.stringify(data)
  }
  log('saveDevice', 'Monitor', logData)
  return request({
    url: 'device',
    method: 'post',
    data
  })
}

export function saveDistribution(data) {
  const logData = {
    data: JSON.stringify(data)
  }
  log('saveDistribution', 'Monitor', logData)
  return request({
    url: 'distribution',
    method: 'post',
    data
  })
}

export function saveAppFilter(data) {
  const logData = {
    data: JSON.stringify(data)
  }
  log('saveAppFilter', 'Monitor', logData)
  return request({
    url: 'app/filter',
    method: 'post',
    data
  })
}

export function deleteDevice(id) {
  const logData = {
    id: id
  }
  log('deleteDevice', 'Monitor', logData)
  return request({
    url: 'device/' + id,
    method: 'delete'
  })
}

export function deleteDistribution(id) {
  const logData = {
    id: id
  }
  log('deleteDistribution', 'Monitor', logData)
  return request({
    url: 'distribution/' + id,
    method: 'delete'
  })
}

export function updateDistributionStatus(id, status) {
  const logData = {
    id: id,
    status: status
  }
  log('updateDistributionStatus', 'Monitor', logData)
  return request({
    url: 'distribution/status/' + id + '/' + status,
    method: 'put'
  })
}

export function listDistribution(query) {
  const logData = {
    query: JSON.stringify(query)
  }
  log('listDistribution', 'Monitor', logData)
  return request({
    url: 'distribution/list',
    method: 'get',
    params: query
  })
}

export function listBehavior(query) {
  const logData = {
    query: JSON.stringify(query)
  }
  log('listBehavior', 'Monitor', logData)
  return request({
    url: 'distributionBehavior/list',
    method: 'get',
    params: query
  })
}

export function listDevice(query) {
  const logData = {
    query: JSON.stringify(query)
  }
  log('listDevice', 'Monitor', logData)
  return request({
    url: 'device/list',
    method: 'get',
    params: query
  })
}

export function listApp(query) {
  const logData = {
    query: JSON.stringify(query)
  }
  log('listApp', 'Monitor', logData)
  return request({
    url: 'app/filter/list',
    method: 'get',
    params: query
  })
}

export function getAllAppOpenData(params) {
  const logData = {
    params: JSON.stringify(params)
  }
  log('getAllAppOpenData', 'Monitor', logData)
  return request({
    url: 'dashboard/app',
    method: 'get',
    params: params
  })
}

export function getAllMotionData(params) {
  const logData = {
    params: JSON.stringify(params)
  }
  log('getAllMotionData', 'Monitor', logData)
  return request({
    url: 'dashboard/motion',
    method: 'get',
    params: params
  })
}

export function getAppOpenSortData(params) {
  const logData = {
    params: JSON.stringify(params)
  }
  log('getAppOpenSortData', 'Monitor', logData)
  return request({
    url: 'dashboard/appOpenSort',
    method: 'get',
    params: params
  })
}

export function getAppMotionSortData(params) {
  const logData = {
    params: JSON.stringify(params)
  }
  log('getAppMotionSortData', 'Monitor', logData)
  return request({
    url: 'dashboard/appMotionSort',
    method: 'get',
    params: params
  })
}

export function getDeviceMotionSortData(params) {
  const logData = {
    params: JSON.stringify(params)
  }
  log('getDeviceMotionSortData', 'Monitor', logData)
  return request({
    url: 'dashboard/deviceMotionSort',
    method: 'get',
    params: params
  })
}

export function getWeeklyData(params) {
  const logData = {
    params: JSON.stringify(params)
  }
  log('getWeeklyData', 'Monitor', logData)
  return request({
    url: 'dashboard/weekly',
    method: 'get',
    params: params
  })
}
